data now is gotten using queries
[RRRRHHHH_Code] / ruralHouses client / src / gui / OwnerRegistrationGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
8
9 import javax.swing.JButton;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JTextField;
14 import javax.swing.border.EmptyBorder;
15
16 import common.AdminInterface;
17
18 import configuration.___IntNames;
19 import domain.Owner;
20
21 public class OwnerRegistrationGUI extends JFrame {
22
23         private JPanel panel;
24         private JTextField nameField;
25         private JTextField userNameField;
26         private AdminInterface am = null;
27         private JTextField passField;
28         private JTextField bank1Field;
29         private JTextField bank2Field;
30         private JTextField bank3Field;
31         private JTextField bank4Field;
32         private JTextField emailField;
33         private JLabel lblWhenAcceptedYou;
34         private JLabel feedback;
35
36         /**
37          * Create the frame.
38          */
39         public OwnerRegistrationGUI() {
40                 
41                 try {
42                         am = (AdminInterface) Naming
43                                         .lookup(___IntNames.AdminManager);
44                 } catch (Exception e1) {
45                         System.out.println("Error accessing remote authentication: "
46                                         + e1.toString());
47                 }
48                 setTitle("Owner registration");
49                 setBounds(100, 100, 500, 400);
50                 panel = new JPanel();
51                 panel.setBorder(new EmptyBorder(5, 5, 5, 5));
52                 setContentPane(panel);
53                 panel.setLayout(null);
54
55                 JLabel nameLb = new JLabel("Name:");
56                 nameLb.setBounds(37, 45, 46, 14);
57                 panel.add(nameLb);
58
59                 nameField = new JTextField();
60                 nameField.setBounds(147, 42, 86, 20);
61                 panel.add(nameField);
62                 nameField.setColumns(10);
63
64                 JLabel lblUsername = new JLabel("Username:");
65                 lblUsername.setBounds(37, 212, 69, 14);
66                 panel.add(lblUsername);
67
68                 userNameField = new JTextField();
69                 userNameField.setBounds(147, 209, 86, 20);
70                 panel.add(userNameField);
71                 userNameField.setColumns(10);
72
73                 JLabel lblPassword = new JLabel("Password:");
74                 lblPassword.setBounds(37, 258, 69, 14);
75                 panel.add(lblPassword);
76
77                 passField = new JTextField();
78                 passField.setBounds(147, 255, 86, 20);
79                 panel.add(passField);
80                 passField.setColumns(10);
81
82                 JLabel lblBankAccount = new JLabel("Bank account:");
83                 lblBankAccount.setBounds(37, 94, 69, 14);
84                 panel.add(lblBankAccount);
85
86                 bank1Field = new JTextField();
87                 bank1Field.setBounds(147, 91, 61, 20);
88                 panel.add(bank1Field);
89
90                 bank2Field = new JTextField();
91                 bank2Field.setBounds(218, 91, 61, 20);
92                 panel.add(bank2Field);
93
94                 bank3Field = new JTextField();
95                 bank3Field.setBounds(289, 91, 32, 20);
96                 panel.add(bank3Field);
97
98                 bank4Field = new JTextField();
99                 bank4Field.setBounds(331, 91, 117, 20);
100                 panel.add(bank4Field);
101
102                 JButton btnSendRegistrationRequest = new JButton(
103                                 "Send registration request");
104                 btnSendRegistrationRequest.setBounds(127, 316, 194, 23);
105                 btnSendRegistrationRequest.addActionListener(new ActionListener() {
106                         public void actionPerformed(ActionEvent arg0) {
107
108                                 jButton_ActionPerformed(arg0);
109                         }
110                 });
111
112                 panel.add(btnSendRegistrationRequest);
113
114                 JLabel lblEmail = new JLabel("E-mail:");
115                 lblEmail.setBounds(37, 155, 46, 14);
116                 panel.add(lblEmail);
117
118                 emailField = new JTextField();
119                 emailField.setBounds(147, 152, 148, 20);
120                 panel.add(emailField);
121                 emailField.setColumns(10);
122
123                 lblWhenAcceptedYou = new JLabel(
124                                 "When accepted you will receive an e-mail");
125                 lblWhenAcceptedYou.setForeground(Color.GREEN);
126                 lblWhenAcceptedYou.setBounds(127, 291, 214, 14);
127                 panel.add(lblWhenAcceptedYou);
128
129                 feedback = new JLabel("");
130                 feedback.setForeground(Color.RED);
131                 feedback.setEnabled(false);
132                 feedback.setBounds(127, 344, 214, 20);
133                 panel.add(feedback);
134         }
135
136         private void jButton_ActionPerformed(ActionEvent e) {
137
138                 Owner own = new Owner(this.nameField.getText(),
139                                 this.bank1Field.getText() + " " + this.bank2Field.getText()
140                                                 + " " + this.bank3Field.getText() + " "
141                                                 + this.bank4Field.getText(), this.emailField.getText());
142
143
144                 try {
145                         if (this.am.addAccountRequest(this.userNameField.getText(),
146                                         this.passField.getText(), own)) {
147                                 this.am.saveInstance();
148                                 this.feedback.setText("Request sended");
149                         } else {
150                                 this.feedback.setText("Can't send the request");
151                         }
152                 } catch (RemoteException e1) {
153                         // TODO Auto-generated catch block
154                         e1.printStackTrace();
155                 }
156
157         }
158 }